<template>

  <!-- <h3>我的歌单</>h3>-->
  <span ><h3 style="padding-bottom: 18px;margin-left: 15px">我的歌单</h3></span>

  <!--我的歌单列表-->
  <!-- 逻辑:循环state.musicList获取用户的所有歌单,然后判断歌单信息,将用户本人创建的歌单渲染到页面-->
  <div v-for="(item,index) in state.musicList" :key="index" class=""  style="width: 100% ;margin-bottom: 15px; height: 75px" >
    <div  v-if="item.creator.userId===this.userId">
      <!--歌单封面-->
      <router-link :to="{path:'/itemMusic',query:{id:item.id}}">
        <div class="img-wrap" >
          <img :src="item.coverImgUrl" alt="" style="height: 75px;width: 75px" />
        </div>
        <div class="info-wrap">
          <!--歌单名称-->
          <span class="" style="" >{{ item.name }}</span><br>
          <!--歌单的歌曲数量-->
          <span class="singer"> {{item.trackCount}}首</span>
        </div>
      </router-link>
    </div>
  </div>

</template>

<script>

import { getUserMusicList } from "@/request/api/home.js";
import { reactive, onMounted } from "vue";
import {mapState} from "vuex";
import {useRoute} from "vue-router";
export default {
  name: "UserMusicList",
  data(){
    return{
      userId:this.$store.state.userID
    }
  },
  computed: {
    ...mapState(["user"]),
  },
  props:[],
  setup() {
    const state = reactive({
      musicList: [], //歌单列表
      creator:[]  //歌单作者
    });
    function changeCount(num) {
      if (num >= 100000000) {
        return (num / 100000000).toFixed(1) + "亿";
      } else if (num >= 10000) {
        return (num / 10000).toFixed(1) + "万";
      }
    }
    onMounted(async () => {
      let id = useRoute().query.userId;
      let res = await getUserMusicList(id);  //获取用户的歌单列表
      console.log(res);
      state.musicList = res.data.playlist; //将歌单赋值给musicList

      res.data.playlist.forEach((item)=>{  //循环歌单获取每个歌单的作者信息传给creator
        let data=item.creator
        state.creator.push(data);
      })
      console.log("creator=")
      console.log(state.creator)
    });
    return { state,changeCount };
  },

}
</script>


<style lang="less" scoped>
.video-wrap {
  width: 100%;
  height: 200px;
  margin-bottom: 20px;
}
singer-info {
  display: flex;
  -webkit-box-align: center;
  align-items: center;
  margin-bottom: 35px;
  height: 100%;
  font-weight: 400;
}
avatar-wrap {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  margin-right: 10px;
  overflow: hidden;
}
.desc {
  font-size: 15px;
  margin-top: 20px;
}
.number {
  color: #bebebe;
  font-size: 14px;
  margin-left: 20px;
}
.data{
  color: #bebebe;
  font-size: 14px;
}
.title{
  margin-top: 20px;
  font-size: 30px;
  margin-bottom: 10px;
}
.name{

}
.video-wrap{
  border-radius: 5px;
  width: 100%;
  height: 390px;
}
.singer{
  padding-left: 14px;
  font-size: 14px;
  color: #c5c5c5;
}
img {
  width: 100%;
  height: 2.4rem;
  border-radius: 0.2rem;

}
.playCount {
  position: absolute;
  z-index: 100;
  right: 0.1rem;
  color: white;
  margin-top: 2rem;

}
.icon {
  width: 0.3rem;
  height: 0.4rem;
}
.img-wrap{
  height: 75px;
  float:left;
  display:inline;
  position: relative;
}
.info-wrap{
  margin-left: 10px;
  width: 50%;
  display:inline
}

.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}


</style>
